package com.zl.tby.screen.enums;

import com.zl.tby.core.base.util.PgMountains;
import com.zl.tby.core.base.util.ToolsUtil;
import com.zl.tby.screen.vo.mountains.TbyReportEventInformation;
import com.zl.tby.screen.vo.mountains.TbyReportEventQuery;
import org.noear.wood.utils.StringUtils;

import java.util.List;
import java.util.Map;

/**
 * @author changpeng
 * @version 1.0
 * @since 2024/10/27 10:06
 */
public enum TbyReportEventEnum {
    woodland("毁坏林地", "xh_yw.xh_event_wfzd_tb") {
        @Override
        public List<TbyReportEventInformation> findList(PgMountains<TbyReportEventInformation> db, TbyReportEventQuery query) {
            StringBuilder builder = new StringBuilder();
            builder.append("select id, guid")
                    .append(" , c_userealname as \"name\", TO_CHAR(uploade_time, 'YYYY-MM-DD HH:MI:SS') as \"reportDate\", place_name as \"address\"")
                    .append(" , sj_miaoshu as \"remark\", to_char(respond_time, 'YYYY-MM-DD HH:MI:SS') as \"handleTime\"")
                    .append(" , respond_user_name as \"handleName\", respond_status as \"respondStatus\", respond_content as \"handleRemark\"")
                    .append(" , longitude as \"longitude\", latitude as \"latitude\", '毁坏林地' as \"eventType\"")
                    .append(" from ").append(this.getTableName()).append(query.getWhere());
            return db.query(builder.toString(), query.getParams(), TbyReportEventInformation.class);
        }

        @Override
        public Long count(PgMountains db, TbyReportEventQuery query) {
            StringBuilder builder = new StringBuilder();
            builder.append("select count(id) as cnum from ").append(this.getTableName()).append(query.getWhere());
            return getCountByList(db.queryMap(builder.toString(), query.getParams()));
        }
    },
    forest("毁坏林木", "xh_yw.xh_event_dflm_tb") {
        @Override
        public List<TbyReportEventInformation> findList(PgMountains<TbyReportEventInformation> db, TbyReportEventQuery query) {
            StringBuilder builder = new StringBuilder();
            builder.append("select id, guid")
                    .append(" , c_userealname as \"name\", TO_CHAR(uploade_time, 'YYYY-MM-DD HH:MI:SS') as \"reportDate\", place_name as \"address\"")
                    .append(" , sj_miaoshu as \"remark\", to_char(respond_time, 'YYYY-MM-DD HH:MI:SS') as \"handleTime\"")
                    .append(" , respond_user_name as \"handleName\", respond_status as \"respondStatus\", respond_content as \"handleRemark\"")
                    .append(" , longitude as \"longitude\", latitude as \"latitude\", '毁坏林木' as \"eventType\"")
                    .append(" from ").append(this.getTableName()).append(query.getWhere());
            return db.query(builder.toString(), query.getParams(), TbyReportEventInformation.class);
        }

        @Override
        public Long count(PgMountains db, TbyReportEventQuery query) {
            StringBuilder builder = new StringBuilder();
            builder.append("select count(id) as cnum from ").append(this.getTableName()).append(query.getWhere());
            return getCountByList(db.queryMap(builder.toString(), query.getParams()));
        }
    },
    fireproof("森林防火", "xh_yw.xh_event_slhz_tb") {
        @Override
        public List<TbyReportEventInformation> findList(PgMountains<TbyReportEventInformation> db, TbyReportEventQuery query) {
            StringBuilder builder = new StringBuilder();
            builder.append("select id, guid")
                    .append(" , c_userealname as \"name\", TO_CHAR(uploade_time, 'YYYY-MM-DD HH:MI:SS') as \"reportDate\", place_name as \"address\"")
                    .append(" , sj_miaoshu as \"remark\", to_char(respond_time, 'YYYY-MM-DD HH:MI:SS') as \"handleTime\"")
                    .append(" , respond_user_name as \"handleName\", respond_status as \"respondStatus\", respond_content as \"handleRemark\"")
                    .append(" , longitude as \"longitude\", latitude as \"latitude\", '森林防火' as \"eventType\"")
                    .append(" from ").append(this.getTableName()).append(query.getWhere());
            return db.query(builder.toString(), query.getParams(), TbyReportEventInformation.class);
        }

        @Override
        public Long count(PgMountains db, TbyReportEventQuery query) {
            StringBuilder builder = new StringBuilder();
            builder.append("select count(id) as cnum from ").append(this.getTableName()).append(query.getWhere());
            return getCountByList(db.queryMap(builder.toString(), query.getParams()));
        }
    },
    animalsPlants("野生动植物", "xh_yw.xh_event_hnbh_tb") {
        @Override
        public List<TbyReportEventInformation> findList(PgMountains<TbyReportEventInformation> db, TbyReportEventQuery query) {
            StringBuilder builder = new StringBuilder();
            builder.append("select id, guid")
                    .append(" , c_userealname as \"name\", TO_CHAR(uploade_time, 'YYYY-MM-DD HH:MI:SS') as \"reportDate\", place_name as \"address\"")
                    .append(" , sj_miaoshu as \"remark\", to_char(respond_time, 'YYYY-MM-DD HH:MI:SS') as \"handleTime\"")
                    .append(" , respond_user_name as \"handleName\", respond_status as \"respondStatus\", respond_content as \"handleRemark\"")
                    .append(" , longitude as \"longitude\", latitude as \"latitude\", '野生动植物' as \"eventType\"")
                    .append(" from ").append(this.getTableName()).append(query.getWhere());
            return db.query(builder.toString(), query.getParams(), TbyReportEventInformation.class);
        }

        @Override
        public Long count(PgMountains db, TbyReportEventQuery query) {
            StringBuilder builder = new StringBuilder();
            builder.append("select count(id) as cnum from ").append(this.getTableName()).append(query.getWhere());
            return getCountByList(db.queryMap(builder.toString(), query.getParams()));
        }
    },
    pest("有害生物", "xh_yw.xh_event_bczh_tb") {
        @Override
        public List<TbyReportEventInformation> findList(PgMountains<TbyReportEventInformation> db, TbyReportEventQuery query) {
            StringBuilder builder = new StringBuilder();
            builder.append("select id, guid")
                    .append(" , c_userealname as \"name\", TO_CHAR(uploade_time, 'YYYY-MM-DD HH:MI:SS') as \"reportDate\", place_name as \"address\"")
                    .append(" , sj_miaoshu as \"remark\", to_char(respond_time, 'YYYY-MM-DD HH:MI:SS') as \"handleTime\"")
                    .append(" , respond_user_name as \"handleName\", respond_status as \"respondStatus\", respond_content as \"handleRemark\"")
                    .append(" , longitude as \"longitude\", latitude as \"latitude\", '有害生物' as \"eventType\"")
                    .append(" from ").append(this.getTableName()).append(query.getWhere());
            return db.query(builder.toString(), query.getParams(), TbyReportEventInformation.class);
        }

        @Override
        public Long count(PgMountains db, TbyReportEventQuery query) {
            StringBuilder builder = new StringBuilder();
            builder.append("select count(id) as cnum from ").append(this.getTableName()).append(query.getWhere());
            return getCountByList(db.queryMap(builder.toString(), query.getParams()));
        }
    },
    naturalDisaster("自然灾害", "xh_yw.xh_event_zrzh_tb") {
        @Override
        public List<TbyReportEventInformation> findList(PgMountains<TbyReportEventInformation> db, TbyReportEventQuery query) {
            StringBuilder builder = new StringBuilder();
            builder.append("select id, guid")
                    .append(" , c_userealname as \"name\", TO_CHAR(uploade_time, 'YYYY-MM-DD HH:MI:SS') as \"reportDate\", place_name as \"address\"")
                    .append(" , sj_miaoshu as \"remark\", to_char(respond_time, 'YYYY-MM-DD HH:MI:SS') as \"handleTime\"")
                    .append(" , respond_user_name as \"handleName\", respond_status as \"respondStatus\", respond_content as \"handleRemark\"")
                    .append(" , longitude as \"longitude\", latitude as \"latitude\", '自然灾害' as \"eventType\"")
                    .append(" from ").append(this.getTableName()).append(query.getWhere());
            return db.query(builder.toString(), query.getParams(), TbyReportEventInformation.class);
        }

        @Override
        public Long count(PgMountains db, TbyReportEventQuery query) {
            StringBuilder builder = new StringBuilder();
            builder.append("select count(id) as cnum from ").append(this.getTableName()).append(query.getWhere());
            return getCountByList(db.queryMap(builder.toString(), query.getParams()));
        }
    },
    noError("核实无异常", "xh_yw.XH_EVENT_ZHHCXC_TB") {
        @Override
        public List<TbyReportEventInformation> findList(PgMountains<TbyReportEventInformation> db, TbyReportEventQuery query) {
            StringBuilder builder = new StringBuilder();
            builder.append("select id, guid")
                    .append(" , c_userealname as \"name\", TO_CHAR(uploade_time, 'YYYY-MM-DD HH:MI:SS') as \"reportDate\", place_name as \"address\"")
                    .append(" , sj_miaoshu as \"remark\", to_char(respond_time, 'YYYY-MM-DD HH:MI:SS') as \"handleTime\"")
                    .append(" , respond_user_name as \"handleName\", respond_status as \"respondStatus\", respond_content as \"handleRemark\"")
                    .append(" , longitude as \"longitude\", latitude as \"latitude\", '核实无异常' as \"eventType\"")
                    .append(" from ").append(this.getTableName()).append(query.getWhere());
            return db.query(builder.toString(), query.getParams(), TbyReportEventInformation.class);
        }

        @Override
        public Long count(PgMountains db, TbyReportEventQuery query) {
            StringBuilder builder = new StringBuilder();
            builder.append("select count(id) as cnum from ").append(this.getTableName()).append(query.getWhere());
            return getCountByList(db.queryMap(builder.toString(), query.getParams()));
        }
    };
    private String value;
    private String tableName;
    TbyReportEventEnum(String value, String tableName) {
        this.value = value;
        this.tableName = tableName;
    }

    public static TbyReportEventEnum getByCode(String code) {
        if (StringUtils.isEmpty(code)) {
            return null;
        }
        TbyReportEventEnum[] array = values();
        for (TbyReportEventEnum e : array) {
            if (e.toString().equals(code)) {
                return e;
            }
        }
        return null;
    }

    public abstract List<TbyReportEventInformation> findList(PgMountains<TbyReportEventInformation> db, TbyReportEventQuery query);

    public abstract Long count(PgMountains db, TbyReportEventQuery query);

    public Long getCountByList(List<Map<String, Object>> dataList) {
        if (dataList != null && dataList.size() > 0) {
            return ToolsUtil.toLong(dataList.get(0).get("cnum") + "", 0L);
        }
        return 0L;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }
}
